package com.Tencent.interview;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author ZhangyiA
 * @describe: 并查集
 * @date 2021/07/03
 */

public class Three_FriendsCircle {

    public int find(int[] parent , int i){
        return parent[i] == -1 ? i : find(parent , parent[i]);
    }

    public void union(int[] parent , int x , int y){
        int x_parent = find(parent , x);
        int y_parent = find(parent , y);
        if(x_parent != y_parent){
            parent[x_parent] = y_parent;
        }
    }

    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        Three_FriendsCircle friendsCircle = new Three_FriendsCircle();
        int T = input.nextInt();
        int[] parent = new int[10000005];
        while(T -- > 0){
            int n = input.nextInt();
            Arrays.fill(parent , -1);
            int max_len = -1;
            for(int i = 0 ; i < n ; i ++){
                int x = input.nextInt();
                int y = input.nextInt();
                int temp = x > y ? x : y;
                max_len = Math.max(max_len , temp);
                friendsCircle.union(parent , x , y);
            }
            int[] count = new int[max_len + 1];
            for(int i = 0 ; i <= max_len ; i ++){
                int father = friendsCircle.find(parent , i);
                count[father] ++;
            }
            int max_count = -1;
            for(int i = 0 ; i <= max_len ; i ++){
                max_count = Math.max(max_count , count[i]);
            }
            System.out.println(max_count);
        }
    }
}
